package top.beiermode.geektime.projects.user.management;

import top.beiermode.geektime.projects.user.domain.User;

import javax.management.MBeanServer;
import javax.management.ObjectName;
import java.lang.management.ManagementFactory;

/**
 * TODO
 *
 * @author Chen Song
 * @since
 */
public class UserMBeanDemo {

    public static void main(String[] args) throws Exception {
        MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
        ObjectName objectName = new ObjectName("top.beiermode.geektime.projects.user.management:type=User");
        User user = new User();
        mBeanServer.registerMBean(createUserBean(user), objectName);
        while (true) {
            Thread.sleep(2000);
            System.out.println(user);
        }
    }

    private static Object createUserBean(User user) {
        return new UserManager(user);
    }

}
